package com.itedge.solutionmanager.web.taskhandler.impl.solution;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;

import com.itedge.solutionmanager.domain.impl.Document;
import com.itedge.solutionmanager.domain.impl.Solution;
import com.itedge.infrastructure.service.process.IProcessService;
import com.itedge.infrastructure.service.task.ITaskService;
import com.itedge.infrastructure.service.taskdata.ITaskDataEntityService;
import com.itedge.infrastructure.stereotype.WebHandler;
import com.itedge.solutionmanager.taskdata.impl.solution.AddDocumentationTaskData;
import com.itedge.solutionmanager.web.convert.ISOFormattingConversionServiceBean;
import com.itedge.infrastructure.web.taskhandler.impl.AbstractTaskDataHandler;

@WebHandler
public class AddDocumentationTaskDataHandler extends AbstractTaskDataHandler<AddDocumentationTaskData, Solution> {
	
	ITaskDataEntityService<AddDocumentationTaskData> addDocumentationTaskDataService;
	
    @Autowired
    protected AddDocumentationTaskDataHandler(ISOFormattingConversionServiceBean conversionService,
    		IProcessService<Solution> solutionProcessService,
    		ITaskDataEntityService<AddDocumentationTaskData> addDocumentationTaskDataService,
    		ITaskService<AddDocumentationTaskData, Solution> addDocumentationTaskService,
    		MessageSource messageSource) {
		super(conversionService, solutionProcessService, addDocumentationTaskDataService, 
				addDocumentationTaskService, messageSource);
		this.addDocumentationTaskDataService = addDocumentationTaskDataService;
	}
	
	@Override
	protected Class<AddDocumentationTaskData> getTaskDataClass() {
		return AddDocumentationTaskData.class;
	}
    
	@Override
	public Map<String,Object> loadTaskData(String taskId, Solution linkedSolution, Boolean forHistory) {
    	AddDocumentationTaskData taskData = addDocumentationTaskDataService.findEntityByProcessTaskId(taskId);
    	if (taskData == null) {
    	    taskData = new AddDocumentationTaskData();  
    	    Document document = new Document();
    	    taskData.setDocument(document);
    	} 
    	taskData.setTaskId(taskId);
    	Map<String,Object> data = new HashMap<String,Object>();
    	data.put("taskData", taskData);
    	return data;
	}
	
}
